forum

Home / DeveloperSection / Forums / How to remove from one list all the items in another?

How to remove from one list all the items in another?

Anonymous User 3083 13-Jun-2013
Hi,

I'm reading a set of rows from a remote database, and a similar set from a local database, and then using RemoveAll to get rid of remote rows that are already present locally...

remote_events = (From a In remote.Events
                          Where ...etc...).ToList
local_events = (From a In local.Events
                            Where ...etc...).ToList
remote_events.RemoveAll(Function (ByVal event_row As Remote_Event)
    (From a In local_events Where a.Identifier = event_row.Identifier).Count > 0)

but this doesn't seem right to me. I don't think I should be counting things when all I really need to do is check whether a match exists. I've tried various usages of IsDBNull and IsNothing but get nonsense. I can't use .Except (as suggested here) because the list elements are not the same type.

Is there a better way of doing this?

Thanks in advance for any recommendations or solutions.

Updated on 14-Jun-2013
I am a content writter !

Can you answer this question?


Answer

1 Answers

Liked By